<%@page import="com.sks.bean.pojo.Users"%>
<%@page import="com.sks.utils.WebUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<div id="comment" class="info_mode mb20">
	<h2><span><a href="javascript:void(0);" onclick="return false;">评论</a></span></h2>
	<div class="info_mode_wrap">
		<div class="clearfix mt30 pb20">
			<div class="fl info_mode_pos" style="width: 94%; margin: 0px 22px 0px;">
				<div class="bigbox">
					<table align="center" width="100%" id="commentTable">
						<tr id="commentTr1" style="display: none;">
							<td width="50%" align="left"><span></span></td>
							<td width="50%" align="right"><span></span></td>
						</tr>
						<tr id="commentTr2" style="display: none;"><td colspan="2"><span></span></td></tr>
						<tr id="commentTr3" style="display: none;"><td align="left" colspan="2"><HR style="FILTER: alpha(opacity=100,finishopacity=0,style=1);  margin-bottom: 20px;" width="100%" color=#987cb9 SIZE=3></td></tr>
						<tr id="commentNullTr" style="display: none;">
							<td width="50%" align="left">暂无评论</td>
						</tr>
						<tr>
							<td colspan="2" height="5">&nbsp;</td>
						</tr>
					</table>
					<table align="center" width="100%" id="">
					<%
						Users user = WebUtil.getUsers(request);
						String userId = user != null ? user.getUserId().toString() : "nobody";
						%>
						<% if (null != user) { %>
						<tr>
							<td colspan="2" width="90%" align="left">
							我来说两句&gt;&gt;<br/>
							<textarea name="content" rows="16" cols="90" style=""></textarea><input type="submit" value="提交"/>
							</td>
						</tr>
						<% } else { %>
						<tr>
							<td colspan="2" width="90%" align="left">
							想说两句？<a href="/sks/privilege/users/logon.do">登录吧</a>
							</td>
						</tr>
						<% } %>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
function toLoginstatus(){
	var user =  '<%=userId%>';
	if(user!="nobody"){
		jQuery.cookie("individual",user,{expires:1});
	}
}
function add_attentioncommunity(cid)
{
	var user =  '<%=userId%>';
    var a=jQuery.cookie('individual');

	var houseId = document.getElementById("houseId").value;
	
	if (user=="nobody" || !a)
	{
		alert("请先登录！");
	    window.location.href='/sks/privilege/users/logon.do';
	}else{
		jQuery.post("/sks/districtCommunity.do", {method:"add_attentioncommunity","houseId":houseId},
	    function (data){
			alert(data[0].message);
			changeCollectLabel(false);
	    }, "json");
	}
};
function del_attentioncommunity(cid)
{
	var user =  '<%=userId%>';
    var a=jQuery.cookie('individual');

	var houseId = document.getElementById("houseId").value;
	
	if (user=="nobody" || !a)
	{
		alert("请先登录！");
	    window.location.href='/sks/privilege/users/logon.do';
	}else{
		jQuery.post("/sks/districtCommunity.do", {method:"del_attentioncommunity","houseId":houseId},
	    function (data){
			alert(data[0].message);
			changeCollectLabel(true);
	    }, "json");
	}
};
function changeCollectLabel(showAdd) {
	var collectHouse = document.getElementById("collectHouse");
	if ( collectHouse ) {
		if (showAdd) {
			collectHouse.innerHTML = "收藏房源";
			collectHouse.onclick = add_attentioncommunity;
		} else {
			collectHouse.innerHTML = "取消收藏";
			collectHouse.onclick = del_attentioncommunity;
		}
	}
}
function isCollected() {
	var houseId = document.getElementById("houseId").value;
	jQuery.post("/sks/districtCommunity.do", {method:"isCollected","houseId":houseId},
    function (data){
		changeCollectLabel(!data[0].message);
    }, "json");
}
function createComment(obj, data, index) {
	var tr1 = document.getElementById("commentTr1").cloneNode(true);
	tr1.style.display = '';
	tr1.getElementsByTagName('span')[0].innerHTML = data.userName + "&nbsp;说";
	tr1.getElementsByTagName('span')[1].innerHTML = data.date;
	var tr2 = document.getElementById("commentTr2").cloneNode(true);
	tr2.style.display = '';
	tr2.getElementsByTagName('span')[0].innerHTML = data.comment;
	var tr3 = document.getElementById("commentTr3").cloneNode(true);
	tr3.style.display = '';
	obj.appendChild(tr1);
	obj.appendChild(tr2);
	obj.appendChild(tr3);
}
function getComment() {
	var houseId = document.getElementById("houseId").value;
	jQuery.post("/user/house/comment.do", {method:"houseComment", "houseId":houseId},
    function (data){
		var obj = document.getElementById('commentTable');
		if ( data.length > 0 ) {
	        for (var i=0; i<data.length; i++) {
	        	createComment(obj, data[i], i);
	        }
		} else {
			var commentNullTr = document.getElementById('commentNullTr');
			if ( commentNullTr ) {
				commentNullTr.style.display = '';
			}
		}
    }, "json");
}
getComment();
</script>
</html>